/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Toolkit;

import java.util.ArrayList;
import javax.swing.JComponent;
import javax.swing.JTextArea;

/**
 *
 * @author bambo_000
 */
public class DataHandler {

    public void weatherDataHandler (String receiveData,JComponent comp) {
        String tempData[] = receiveData.split(",");
        ((JTextArea) comp).setText("");
        if (tempData.length == 8) {
            ((JTextArea) comp).append("Weather:             " + tempData[1] +"\n");
            ((JTextArea) comp).append("Wind Direction:      " + tempData[2] +"\n");
            ((JTextArea) comp).append("Wind Speed:          " + tempData[3] +"\n");
            ((JTextArea) comp).append("Humidity(%):         " + tempData[4] +"\n");
            ((JTextArea) comp).append("Air Temperature(℃): " + tempData[5] +"\n");
            ((JTextArea) comp).append("Air Pressure:        " + tempData[6] +"\n");
            ((JTextArea) comp).append("Visibility(Meter):   " + tempData[7] +"\n");          
        }       
    }
    
    public ArrayList<String> flightDataHandler (String receiveData,JComponent comp) {
        String tempData[] = receiveData.split(",");
        ArrayList<String> tempArrayList = new ArrayList<>();
        ((JTextArea) comp).setText("");
        
        if (tempData.length == 6) {
            ((JTextArea) comp).append("Flight:               " + tempData[0] +"\n");
            ((JTextArea) comp).append("Registration:         " + tempData[1] +"\n");
            ((JTextArea) comp).append("Departure:            " + tempData[2] +"\n");
            ((JTextArea) comp).append("Destination:          " + tempData[3] +"\n");
            ((JTextArea) comp).append("Departure Date&Time:  " + tempData[4] +"\n");
            ((JTextArea) comp).append("Destination Date&Time:" + tempData[5] +"\n");
            
            tempArrayList.add(tempData[0]);
            tempArrayList.add(tempData[1]);
        }    
        
        return tempArrayList;
    }
    
    public void runwayDataHandler (String receiveData,JComponent comp) {
        String tempRunwayData[] = receiveData.split(";");
        ((JTextArea) comp).setText("");
        System.out.println(tempRunwayData[0]);
        for (int i = 0; i< 2 ; i++) {
            String [] tempRunwayInfo = tempRunwayData[i].split(",",3);
            
            if (i == 0) {
                ((JTextArea) comp).append("Left Runway:\n");
                ((JTextArea) comp).append("Status: " + tempRunwayInfo[1] +"\n");
                ((JTextArea) comp).append("Flight: " + tempRunwayInfo[2] +"\n");
                ((JTextArea) comp).append("=====================\n");
            } else {
                ((JTextArea) comp).append("Right Runway:\n");
                ((JTextArea) comp).append("Status: " + tempRunwayInfo[1] +"\n");
                ((JTextArea) comp).append("Flight: " + tempRunwayInfo[2] +"\n");
            }
            
        }
    }
}
